package com.hockeo.client.ui.base;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.hockeo.client.model.JSData;
import com.hockeo.client.model.JSSimpleData;

/**
 * Simple combo box that uses JSSimpleData objects as models
 *
 * @version $Id$
 * @author jjanke
 */
public class VHSimpleComboBox extends VHComboBox
{
  public VHSimpleComboBox()
  {
    final ComboBox<JSData> combobox = getCombobox();

    combobox.setValueField( JSSimpleData.PARAM_ID );
    combobox.setDisplayField( JSSimpleData.PARAM_LABEL );
  }

  /**
   * Sets the simple models that should be selectable in this combobox. Any previously
   * loaded models will be discarded when this method is called.
   *
   * @param aModels the models to be selectable, the first passed model will be used as
   *          default value
   */
  public void setSimpleModels( JSSimpleData... aModels )
  {
    if ( aModels.length == 0 )
      return;

    final ListStore<JSData> store = getStore();

    store.removeAll();

    for ( JSSimpleData model : aModels )
      store.add( model );

    setDefault( aModels[0] );
    setInitialised( true );
  }
}
